@extends('home.personal.userlayout')
@section('title','资料修改')
@section('style')
    <link rel="stylesheet" href="{{ asset('/home/css/edit.css')}}?version=2"/>
@endsection
@section('content')
    <form action="{{url('doLogin')}}" method="post">
        {{ csrf_field() }}
        <div class="l1">
            <span class="label">头像：</span>
            <img src="{{asset('/home/images/u14.png')}}" class="rightimg">
            <img src="{{asset($user->img)}}" alt="" class="myimg" onclick="upload.click()">
            <input type="file" name="headimgs" class="upload" id="upload"  onchange="sc(this);" style="display: none;">
        </div>
        <div class="l1">
            <span class="label">姓名：</span>
            <img src="{{asset('/home/images/u14.png')}}" class="rightimg">
            <input class="input" type="text" name="name"  value="{{$user->name}}">
        </div>
        <div class="l1">
            <span class="label">手机号：</span>
            <img src="{{asset('/home/images/u14.png')}}" class="rightimg">
            <input class="input" type="text" name="mobile"  value="{{$user->mobile}}">
        </div>
        <div class="l1">
            <span class="label">修改密码：</span>
            <img src="{{asset('/home/images/u14.png')}}" class="rightimg">
            <input class="input" type="password" name="password"  value="">
        </div>
        

        <div class="btn">
            <a href="{{url('layout')}}" class="layout">退出登录</a>
        </div>
    </form>

@endsection

@section('script')
    <script>
        var url = "{{ url('/personal') }}";
        $('.head .left').attr('href',url);

        function sc() {
            var formData = new FormData();
            var img = document.getElementById('upload');
            var fileObj = img.files[0];
            formData.append('headimgs',fileObj);
            $.ajax({
                url:"{{ url('admin/upload_img') }}",
                type:'post',
                data:formData,
                async:false,
                contentType : false,
                processData : false,
                success:function (data) {
                    $('input[name=img]').val(data.url);
                    $('.myimg').attr('src',data.url);
                },
                error:function () {
                    console.log('no')
                },
                dataType:'json'

            })
        }

        $('.input').on('change',function () {
            var name = $('input[name=name]').val();
            var mobile = $('input[name=mobile]').val();
            var password = $('input[name=password]').val();
            $.ajax({
                url:"{{ url('edit_post') }}",
                type:'post',
                data:{name:name,mobile:mobile,password:password},
                success:function (data) {
                    console.log(data);
                },
                error:function () {
                    console.log('no');
                },
                dataType:'json'
            })
        })
    </script>

@endsection